package cn.tradewin.advisor.pages.project.plan;

import java.util.List;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import cn.tradewin.advisor.exceptions.DBException;
import cn.tradewin.advisor.persist.model.Wbs;
import cn.tradewin.advisor.persist.services.WbsService;

public class WbsManagement {
	
	@Inject
	private Messages messages;
	
	@Inject
	private BeanModelSource beanModelSource;
	
	@Property
	private BeanModel<Wbs> beanModel;
	
	@Inject
	private WbsService wbsService;
	
	@Property
	private List<Wbs> wbses;
	
	@Property
	private Wbs wbs;
	
	@SetupRender
	void setupRender() throws DBException {
		beanModel = beanModelSource.createDisplayModel(Wbs.class, messages);
		beanModel.add("action", null);
		beanModel.include("id", "task","taskType", "category", "owner", "playStart", "playEnd", "start", "end", "status");
		beanModel.get("id").sortable(false);
		beanModel.get("task").sortable(false);
		beanModel.get("taskType").sortable(false);
		beanModel.get("category").sortable(false);
		beanModel.get("owner").sortable(false);
		beanModel.get("playStart").sortable(false);
		beanModel.get("playEnd").sortable(false);
		beanModel.get("start").sortable(false);
		beanModel.get("end").sortable(false);
		beanModel.get("status").sortable(false);
		
	}	
	
	@OnEvent(EventConstants.PREPARE_FOR_RENDER)
	void prepareForRender() throws DBException {
		wbses = wbsService.getAllWbses();
	}

}
